package com.second.market.service.impl;

import com.alibaba.cloud.commons.lang.StringUtils;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.second.common.pojo.RR;
import com.second.market.mapper.AdvertiseMapper;
import com.second.market.mapper.CustomerPlaceMapper;
import com.second.market.pojo.entity.Advertise;
import com.second.market.pojo.vo.AdvertiseVo;
import com.second.market.service.AdvertiseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * @program: clms-second
 * @description: 广告的控制层
 * @author: 邓衡
 * @create: 2021-07-23 17:41
 **/
@Service
public class AdvertiseServiceImpl implements AdvertiseService{
    @Autowired
    private AdvertiseMapper advertiseMapper;


    @Autowired CustomerPlaceMapper customerPlaceMapper;



    @Override
    public RR finAllAdvertiseByPage(Integer currentPage, Integer pageSize, AdvertiseVo advertiseVo) {
        Page<Advertise> page=new Page<>(currentPage,pageSize);
        QueryWrapper<Advertise> wrapper=new QueryWrapper<>();
        if (StringUtils.isNotEmpty(advertiseVo.getName())){
            wrapper.like("name",advertiseVo.getName());
        }

        Page<Advertise> page1 = advertiseMapper.selectPage(page, wrapper);
        return RR.ok().put("records",page1.getRecords()).put("total",page1.getTotal());
    }



    @Override//添加
    public RR insert(Advertise advertise) {
        int i=advertiseMapper.insert(advertise);
        return RR.ok();
    }
    @Override//修改
    public RR update(Advertise advertise) {
        int i=advertiseMapper.updateById(advertise);
        return RR.ok();
    }

    @Override//根据id回显
    public RR selectById(Integer id) {
        Advertise advertise = advertiseMapper.selectById(id);
        return RR.ok().put("huixian",advertise);
    }

    @Override//删除
    public RR delete(Integer id) {
        int i=advertiseMapper.deleteById(id);
        return RR.ok();
    }

    @Override
    public RR update(Integer status, Integer advertiseid) {
         advertiseMapper.update(status, advertiseid);
         return RR.ok();
    }

    @Override
    public List<Map> selectPlace() {
        return advertiseMapper.selectPlace();
    }


}
